import router from "@/router";
import { Toast, Notify } from 'vant'
import { Http } from "./HttpClient";
import Vue from "vue";
function getUserInfo() {
    console.log("****************权限调用用户信息接口");
    return new Promise(async (resolve, reject) => {
        Http.instance().postJSON({
            url: '/gmms-server/externalController',
            data: {
                route: 'CommonController_getUserInfoByToken',
                params: {},
            },
        }).then(({ content })=>{
            console.log("****************权限调用用户信息接口， 成功");
            if (content) { 
                content['dept']=content['whbzid']
                content['deptmc']=content['whbz']
                content['userName']=content['name']
                content['userId']=content['id']
                content['ssdsmc']=content['ssds']
                content['ssds']=content['ssdsid']
                content['ywdwmc']=content['ywdw']
                content['ywdw']=content['ywdwid']
                console.log(content)
                Vue.prototype.$dealMsg( 'SDXJ_USER_INFO',JSON.stringify(content))
                Vue.prototype.$dealMsgLS('SDXT_LOACL_USER_INFO', JSON.stringify(content));
            } else {
                Toast.fail('获取用户信息失败')
            }
            getConfigQuery()
            resolve()     
        }).catch((err)=>{
            console.log("****************权限调用用户信息接口， 失败");
            console.log(err)
            Notify({
                type: 'danger',
                message: '获取用户信息失败, 请检查网络或者请联系管理员',
            })
            resolve()     
        }) 
    })

}
function getConfigQuery() { 
    return new Promise(async (resolve, reject) => {
        Http.instance().postJSON({
            url: '/gmms-server/externalController',
            data: {
                route: 'CommonController_queryConfig', 
                params: {configKey:'TRAIL_INTER_CYCLE,SDTD_SAOU,GPS_SIGN_DIST,HS_IP,Sm4IvStr,SDJC_SAOU,HS_SAOU,SDJX_SAOU,SDQD_SAOU,PIC_SAOU,SDYGLZ_SAOU,SDXL_SAOU,WW_IMAGE_SERVER,Sm4KeyStr,SDYH_SAOU,SDSSP_SAOU,SDQX_SAOU'},
          
            },
        }).then(({ content })=>{
            dealConfigQuery(content);
            resolve()     
        }).catch((err)=>{
            console.log(err) 
            resolve()     
        })  
    }) 
    
} 
function dealConfigQuery(content) { 
    Vue.prototype.$dealMsgLS('SDXT_LOACL_queryConfig', JSON.stringify(content));
    // Vue.prototype.$dealMsg("UPLOAD_URL",JSON.stringify({ ...content,url:content["WW_IMAGE_SERVER"],saou:content["SDJX_SAOU"]}));
    Vue.prototype.$dealMsg("HS_URL",JSON.stringify({url:content["HS_IP"],saou:content["HS_SAOU"]}));
    Vue.prototype.$dealMsg("SM4_DATA",JSON.stringify({Sm4KeyStr:content["Sm4KeyStr"],Sm4IvStr:content["Sm4IvStr"]}));
    Vue.prototype.$dealMsg("GPS_SIGN_DIST",content["GPS_SIGN_DIST"] );
    Vue.prototype.$dealMsg("TRAIL_INTER_CYCLE",content["TRAIL_INTER_CYCLE"] ); 
} 
router.beforeEach(async (to, from, next) => {
    // if (!userInfo) {
    //     console.log("调用获取用户接口");
    //     await getUserInfo()
    // }
    next()
})